﻿<UserControl x:Class="ModernUILogViewer.Content.ContentExternalEditor"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:mui="http://firstfloorsoftware.com/ModernUI"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
             xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
             xmlns:helper="clr-namespace:ModernUILogViewer.Elements.Helpers"
             DataContext="{Binding Source={StaticResource mainVM}, Path=ExternalEditorVM}"
             mc:Ignorable="d" 
             d:DesignHeight="500" d:DesignWidth="600"
             >
    <Grid >
        <StackPanel helper:NotifierPanelHelper.EnableNotifier="True">
            <TextBlock Text="EXTERNAL PROGRAM EXECUTABLE" Style="{StaticResource Heading2}" />
            <StackPanel Orientation="Horizontal" Margin="{StaticResource DefaultTopMargin}">
                <TextBox x:Name="txtboxpath" IsReadOnly="True" Text="{Binding ExePath, Mode=OneWay}" MinWidth="300" />
                <Button Content="Browse" Command="{Binding OpenFileDialog}" Margin="{StaticResource DefaultLeftMargin}" />
                <Button Content="Clear" Command="{Binding Clear}" Margin="{StaticResource DefaultLeftMargin}" />
            </StackPanel>
            <TextBlock Text="COMMAND LINE ARGUMENTS" Style="{StaticResource Heading2}" Margin="{StaticResource DefaultTopMargin}" />
            <TextBox Text="{Binding CommandArgs,Mode=TwoWay}" HorizontalAlignment="Left" Width="300" Margin="{StaticResource DefaultTopMargin}"  />
            <TextBlock Text="CONTEXT ARGUMENTS" Style="{StaticResource Heading2}" Margin="{StaticResource DefaultTopMargin}" />
            
            <Border BorderThickness="1" HorizontalAlignment="Left" Width="300" BorderBrush="{DynamicResource ButtonBorder}" Margin="0, 8, 0, 0">
                <ListBox x:Name="comboArgument" DisplayMemberPath="Value" SelectedValuePath="Key" ItemsSource="{Binding ArgumentList, Mode=OneTime}" Margin="{StaticResource DefaultMargin}" />
            </Border>

            <StackPanel Orientation="Horizontal" Grid.Row="9" Grid.ColumnSpan="2" Margin="0, 12, 0, 0">
                <Button x:Name="savebtn" IsEnabled="False" Content="Save" Command="{Binding Source={StaticResource settingsmanager}, Path=SaveExtEditorSettings}" CommandParameter="{Binding}" />
                <Button x:Name="reloadbtn"  IsEnabled="False" Content="Reload" Command="{Binding Source={StaticResource settingsmanager}, Path=ReloadExtEditorSettings}" CommandParameter="{Binding}" Margin="{StaticResource DefaultLeftMargin}" />
            </StackPanel>

        </StackPanel>

    </Grid>

    <i:Interaction.Triggers>
        <!-- needed for isReadOnly textbox -->
        <i:EventTrigger EventName="TextChanged" SourceName="txtboxpath">
            <ei:ChangePropertyAction TargetName="savebtn" PropertyName="IsEnabled" Value="True" />
            <ei:ChangePropertyAction TargetName="reloadbtn" PropertyName="IsEnabled" Value="True" />
        </i:EventTrigger>
        
        <i:EventTrigger EventName="SettingsSaved" SourceObject="{StaticResource settingsmanager}">
            <ei:ChangePropertyAction TargetObject="{Binding ElementName=savebtn}" PropertyName="IsEnabled" Value="False" />
            <ei:ChangePropertyAction TargetObject="{Binding ElementName=reloadbtn}" PropertyName="IsEnabled" Value="False" />
        </i:EventTrigger>
        <i:EventTrigger EventName="SettingsReloaded" SourceObject="{StaticResource settingsmanager}">
            <ei:ChangePropertyAction TargetObject="{Binding ElementName=reloadbtn}" PropertyName="IsEnabled" Value="False" />
            <ei:ChangePropertyAction TargetObject="{Binding ElementName=savebtn}" PropertyName="IsEnabled" Value="False" />
        </i:EventTrigger>
        <i:EventTrigger EventName="MouseDoubleClick" SourceObject="{Binding ElementName=comboArgument}">
            <i:InvokeCommandAction Command="{Binding AddArgumentToCommand}" CommandParameter="{Binding ElementName=comboArgument, Path=SelectedValue}" />
        </i:EventTrigger>
        <helper:RoutedEventTrigger RoutedEvent="{x:Static helper:NotifierPanelHelper.ChildrenChangedEvent}">
            <ei:ChangePropertyAction TargetName="savebtn" PropertyName="IsEnabled" Value="True" />
            <ei:ChangePropertyAction TargetName="reloadbtn" PropertyName="IsEnabled" Value="True" />
        </helper:RoutedEventTrigger>
    </i:Interaction.Triggers>
    
</UserControl>
